<%@page contentType="text/html" pageEncoding="UTF-8" 
        import="java.io.*,
        java.util.*,
        java.sql.*, 
        javax.sql.*, 
        org.brickred.socialauth.*"%>
<%

    String text = request.getParameter("wordList");

    String listName = request.getParameter("listName");
    String note = request.getParameter("note");

    String uid = (String) session.getAttribute("uid");
    if (uid == null || text == null) {
        return;
    }
    if (listName == null) {
        listName = (new java.util.Date()).toString().replace("\\W", "_");
    }
     if (text.length() >1000) text = text.substring(0,1000);
    Connection con = com.elookinto.wordlist.Util.getCon();
    try {
        if (note != null && note.trim().length() > 0) {
             note = note.trim();
        if (note.length() >1000) note = note.substring(0,1000);
            //con.createStatement().execute();
            PreparedStatement st = con.prepareStatement("insert into note (listname, uid, txt) values(?,?,?) ");
            st.setString(1, listName);
            st.setString(2, uid);
            st.setString(3, note);
            st.executeUpdate();
        }
        //System.out.println("here is====" + text.length());
        //System.out.println("here is ===" + text);
    } catch (Exception e) {
        e.printStackTrace();
    }

    PreparedStatement st = null;
    try {
        st = con.prepareStatement("insert into wordlist (word, listname, uid, insert_time) values(?,?,?, current_timestamp) ");
    } catch (Exception e) {
        e.printStackTrace();
    }
    int beginQuote = -1;
    int endQuote = -1;
    for (int i = 0; i < text.length(); i++) {
        String word = text.substring(i, i + 1);
        if ((text.charAt(i) == '\"'  ||  text.charAt(i) =='\u201C' ||  text.charAt(i) =='\u301D') && beginQuote == -1) {
            beginQuote = i;
            continue;
        }
        if ((text.charAt(i) == '\"' ||  text.charAt(i) =='\u201D' ||  text.charAt(i) =='\u301E') && beginQuote >= 0) {
            endQuote = i;
            System.out.println( beginQuote + "   ---" + endQuote);
            word = text.substring(beginQuote + 1, endQuote);
            beginQuote =  - 1;
            endQuote = -1;
        }

        System.out.println("word=" + word);
        if (beginQuote>=0 && endQuote <0) {
            continue;
        }
        if (Character.UnicodeBlock.of(word.charAt(0)) != Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS) {
            continue;
        }
        st.setString(1, word);
        st.setString(2, listName);
        st.setString(3, uid);
        try {
            st.execute();
        } catch (Exception e) {
            //e.printStackTrace();
        }
    }
    st.close();
    con.close();
    out.println("saved");

%>
